#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>

int main(void) {
    int n;
    scanf("%d", &n);
    for (int p = 0; p < n; p++) {
        int k;
        scanf("%d", &k);
        char** strings = (char**) calloc(k, sizeof(char*));
        int min = INT_MAX;
        for(int i = 0; i < k; i++) {
            strings[i] = (char*) calloc(201, sizeof(char));
            scanf(" %s", strings[i]);
            int len = strlen(strings[i]);
            min = len < min ? len : min;
        }
        int common = min;
        for(int i = 1; i < k; i++) {
            int pos = 0;
            for(char* pnt = strings[i]; *pnt != '\0' && pos < common; pnt++, pos++) {
                if (*pnt != strings[0][pos]) {
                    common = pos;
                }
            }
        }
        printf("Case %d: ", p + 1);
        for(int i = 0; i < common; i++) {
            putchar(strings[0][i]);
        }
        putchar('\n');
        for(int i = 0; i < k; i++) {
            free(strings[i]);
        }
        free(strings);
    }
    return 0;
}
